package com.lry.filter;

import com.lry.filter.client.ClientFilter;
import com.lry.filter.server.ServerFilter;
import com.lry.protocol.RpcMessage;
import com.lry.spi.EnhancedServiceLoader;

import java.util.List;

public class FilterFactory {

    public static void executeAllServerFilter(RpcMessage rpcMessage){
        for (ServerFilter serverFilter : getAllServerFilter()) {
            serverFilter.filter(rpcMessage);
        }
    }
    private static List<ServerFilter> getAllServerFilter(){
        return EnhancedServiceLoader.loadAll(ServerFilter.class);
    }

    public static void executeAllClientFilter(RpcMessage rpcMessage){
        for (ClientFilter clientFilter : getAllClientFilter()) {
            clientFilter.filter(rpcMessage);
        }
    }
    private static List<ClientFilter> getAllClientFilter(){
        return EnhancedServiceLoader.loadAll(ClientFilter.class);
    }


}
